package com.jysz.webcore.ssh.orm.hibernate.mysql;

import java.util.List;

import org.hibernate.QueryException;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.engine.Mapping;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.type.LongType;
import org.hibernate.type.Type;

public class LeftMoveFunction implements SQLFunction {


	@Override
	public Type getReturnType(Type type, Mapping mapping) throws QueryException {
		return LongType.INSTANCE;
	}

	@Override
	public boolean hasArguments() {
		return true;
	}

	@Override
	public boolean hasParenthesesIfNoArguments() {
		return true;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public String render(Type type, List args, SessionFactoryImplementor factory)
			throws QueryException {
		if (args.size() != 2) {
		    throw new IllegalArgumentException("right_move requires 2 arguments!");
		   }
		   return "(" + args.get(0).toString() + " << " + args.get(1).toString() + ")";
	}

}
